# @ModuleName: userbrowser
# @Author: zxl
# @Time: 2024/6/15 9:10'
import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service


class UserBrowser:
    driver = None

    def __init__(self, browser_name='chrome', path='../../chromedriver.exe'):
        try:
            if browser_name.lower() == 'chrome':
                service_path = Service(path)
                self.driver = webdriver.Chrome(service=service_path)
                self.driver.implicitly_wait(5)
                self.driver.maximize_window()
                UserBrowser.driver = self.driver
            elif browser_name.lower() == 'edge':
                service_path = Service(path)
                self.driver = webdriver.Edge(service=service_path)
                self.driver.implicitly_wait(5)
                self.driver.maximize_window()
                UserBrowser.driver = self.driver
            elif browser_name.lower() == 'firefox':
                pass
            else:
                print('support:chrome,edge,firefox')
        except Exception as e :
            print(f'browser is error:{e}')


    @classmethod
    def quit(cls):
        time.sleep(3)
        cls.driver.quit()

